export function generateTagsHtml(tags: string[] | undefined): string {
  if (!tags || !Array.isArray(tags) || tags.length === 0) {
    return '<div class="tags-empty">暂无标签</div>'
  }

  return `
    <div class="tags-container">
      ${tags
        .map(tag => {
          const escapedTag = escapeHtml(tag)
          return `<span class="tag-item" title="点击查看相关记录" data-tag="${escapedTag}">${escapedTag}</span>`
        })
        .join('')}
    </div>
  `
}

function escapeHtml(text: string): string {
  if (!text) return ''
  return text.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;')
}
